package com.nuoniu.sibanyun.controller.cm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.cm.ContractType;
import com.nuoniu.sibanyun.service.cm.IContractTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  合同分类前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/cm/contractType")
@Api(tags = "合同分类管理")
public class ContractTypeController extends BaseController {

    @Autowired
    private IContractTypeService contractTypeService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList() {
        return HttpResult.ok(contractTypeService.getList());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ContractType contractType) {
        if(StringUtils.isBlank(contractType.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }

        if(StringUtils.isBlank(contractType.getCode())) {
            throw new NuoNiuException("名称不能为空");
        }

        contractTypeService.saveContractType(contractType);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        contractTypeService.removeById(id);
        return HttpResult.ok();
    }
}
